import { Graphics, Vec2 } from "cc";

/**
 * 绘制2D类, 简化Graphics的使用
 */
export class Draw2D {
    private _graghics: Graphics;
    public get graghics(): Graphics {
        return this._graghics;
    }
    public set graghics(value: Graphics) {
        this._graghics = value;
    }
    
    constructor(graghics_: Graphics) {
        this._graghics = graghics_
    }

    /**
     * 清空
     */
    public clear() {
        this.graghics.clear()
    }

    /**
     * 画线
     * @param p1 起点
     * @param p2 终点
     */
    public line(p1: Vec2, p2: Vec2) {
        this.graghics.moveTo(p1.x, p1.y);
        this.graghics.lineTo(p2.x, p2.y);
        this.graghics.stroke();
    }

    /**
     * 画圆
     * @param point 中心点
     * @param radius 半径
     */
    public circle(point: Vec2, radius: number = 5) {
        this.graghics.circle(point.x, point.y, radius);
        this.graghics.fill();
    }
}